package com.beadhouse.customer.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.beadhouse.common.dto.JSONResponse;
import com.beadhouse.customer.ao.CustomerAo;
import com.beadhouse.customer.service.CustomerService;
import com.beadhouse.entity.CustomerEntity;
import com.github.pagehelper.PageInfo;
;

@Controller
@RequestMapping("/api/customer")
public class CustomerManageCountroller {
	@Autowired
	CustomerService CustomerService;
	@GetMapping("/selectAll")
	@ResponseBody
	public JSONResponse selectList(CustomerAo ao) throws Exception{
		
		List<CustomerEntity> e=CustomerService.selectCustomerList(ao);		
		return JSONResponse.ok(e);
	} 
	@GetMapping("/selectAllByPage")
	@ResponseBody
	public JSONResponse selectListByPage(CustomerAo ao,String pageNo) throws Exception{
		
		PageInfo<CustomerEntity> e=CustomerService.selectCustomerList1(ao,pageNo);		
		return JSONResponse.ok(e);
	}    
	
	@GetMapping("/update")
	@ResponseBody
	public JSONResponse updateCustomer(CustomerAo ao) throws Exception{		
		CustomerService.updateCustomer(ao);		
		return JSONResponse.ok("ok");
	}
	@GetMapping("/selectCustomer")
	@ResponseBody
	public JSONResponse selectCustomer(CustomerAo ao) throws Exception{		
		CustomerEntity e=CustomerService.selectCutomerOne(ao);		
		return JSONResponse.ok(e);
	}
	@GetMapping("/addCustomer")
	@ResponseBody
	public JSONResponse addCustomer(CustomerAo ao) throws Exception{		
		CustomerService.addCustomer(ao);		
		return JSONResponse.ok("ok");
	}
	@GetMapping("/retreatCustomer")
	@ResponseBody
	public JSONResponse retreatCustomer(CustomerAo ao) throws Exception{		
		CustomerService.retreatCustomer(ao);		
		return JSONResponse.ok("ok");
	}
	@GetMapping("/delete")
	@ResponseBody
	public JSONResponse deleteCustomer(CustomerAo ao) throws Exception{		
		CustomerService.deleteCustomer(ao);	
		return JSONResponse.ok("ok");
	}

}
